package customerEnter.Frame.JDBCDao.UseQuery;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;

import customerEnter.Frame.DaoDataTransmission.DaoFramePameTransmission;
import customerEnter.Frame.JDBCDao.Interface.DaoFrameUseTypeInterface;
import customerEnter.Frame.Utils.Log4j;

public class DaoFrameUseTypeMapImpl implements DaoFrameUseTypeInterface<Map<String, Object>> {

	@Override
	public <T, K> Map<String, Object> useDaoFrameDataType(DaoFramePameTransmission<T, K> daoFramePameTransmission) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<String> list = new ArrayList<String>();
		try {
			SqlRowSet sqlRowSet = daoFramePameTransmission.sqlRowSet;
			// ResultSet sqlRowSet = daoFramePameTransmission.getRs();
			SqlRowSetMetaData sqlRowSetMetaData = sqlRowSet.getMetaData();
			int in = sqlRowSetMetaData.getColumnCount();
			for (int i = 1; i <= in; i++) {
				list.add(sqlRowSetMetaData.getColumnName(i));
			}
			while (sqlRowSet.next()) {
				for (String string : list) {
					map.put(string, sqlRowSet.getObject(string));
				}
				break;
			}
		} catch (Exception e) {
			Log4j.setLog4j(getClass());
			Log4j.Log4JOutError("返回map出錯:" + e.getMessage());
		}
		return map;
	}

}
